package com.liuhongwei.test.entity.assemble;

import java.util.Date;
import com.alibaba.fastjson.JSONObject;
import com.liuhongwei.test.utils.CHUUIDUtils;
import com.liuhongwei.test.utils.AppStringUtils;
import com.liuhongwei.test.entity.po.SysCountry;
import com.liuhongwei.test.entity.query.SysCountryQuery;
/**
 * 国家表赋值工具
 * @auther: 刘洪玮
 * @date: 2025-07-24 11:32
 */
public class SysCountryAssemble {

	/**
	 * JSON对象转查询对象
	 */
	public static SysCountryQuery toPageQuery(JSONObject jsonObject) {
		SysCountryQuery sysCountryQuery = new SysCountryQuery();

		Integer currentPage = jsonObject.getInteger("currentPage");
		Integer pageSize = jsonObject.getInteger("pageSize");
		sysCountryQuery.setCurrentPage(currentPage == null ? 1 : currentPage);
		sysCountryQuery.setPageSize(pageSize == null ? 15 : pageSize);

		sysCountryQuery.setUuid(AppStringUtils.formatEmptyToNull(jsonObject.getString("uuid")));
		sysCountryQuery.setCreateTime(jsonObject.getDate("createTime"));
		sysCountryQuery.setUpdateTime(jsonObject.getDate("updateTime"));
		sysCountryQuery.setCode(AppStringUtils.formatEmptyToNull(jsonObject.getString("code")));
		sysCountryQuery.setNameCn(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameCn")));
		sysCountryQuery.setNameEn(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameEn")));
		sysCountryQuery.setUuidFuzzy(AppStringUtils.formatEmptyToNull(jsonObject.getString("uuidFuzzy")));
		sysCountryQuery.setCreateTimeBegin(jsonObject.getDate("createTimeBegin"));
		sysCountryQuery.setCreateTimeEnd(jsonObject.getDate("createTimeEnd"));
		sysCountryQuery.setUpdateTimeBegin(jsonObject.getDate("updateTimeBegin"));
		sysCountryQuery.setUpdateTimeEnd(jsonObject.getDate("updateTimeEnd"));
		sysCountryQuery.setCodeFuzzy(AppStringUtils.formatEmptyToNull(jsonObject.getString("codeFuzzy")));
		sysCountryQuery.setNameCnFuzzy(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameCnFuzzy")));
		sysCountryQuery.setNameEnFuzzy(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameEnFuzzy")));
		return sysCountryQuery;
	}

	/**
	 * 分页查询对象转JSON对象
	 */
	public static JSONObject toPageJSONObject(SysCountry sysCountry) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("uuid", sysCountry.getUuid());
		jsonObject.put("createTime", sysCountry.getCreateTime());
		jsonObject.put("updateTime", sysCountry.getUpdateTime());
		jsonObject.put("code", sysCountry.getCode());
		jsonObject.put("nameCn", sysCountry.getNameCn());
		jsonObject.put("nameEn", sysCountry.getNameEn());
		return jsonObject;
	}

	/**
	 * 查询对象转JSON对象
	 */
	public static JSONObject toJSONObject(SysCountry sysCountry) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("uuid", sysCountry.getUuid());
		jsonObject.put("createTime", sysCountry.getCreateTime());
		jsonObject.put("updateTime", sysCountry.getUpdateTime());
		jsonObject.put("code", sysCountry.getCode());
		jsonObject.put("nameCn", sysCountry.getNameCn());
		jsonObject.put("nameEn", sysCountry.getNameEn());
		return jsonObject;
	}

	/**
	 * JSON对象转新增对象
	 */
	public static SysCountry toSysCountryInsert(JSONObject jsonObject) {
		SysCountry sysCountry = new SysCountry();
		sysCountry.setUuid(CHUUIDUtils.generateUUID());
		sysCountry.setCreateTime(new Date());
		sysCountry.setUpdateTime(new Date());
		sysCountry.setCode(AppStringUtils.formatEmptyToNull(jsonObject.getString("code")));
		sysCountry.setNameCn(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameCn")));
		sysCountry.setNameEn(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameEn")));
		return sysCountry;
	}

	/**
	 * JSON对象转更新对象
	 */
	public static SysCountry toSysCountryUpdate(JSONObject jsonObject) {
		SysCountry sysCountry = new SysCountry();
		sysCountry.setUuid(AppStringUtils.formatEmptyToNull(jsonObject.getString("uuid")));
		sysCountry.setUpdateTime(new Date());
		sysCountry.setCode(AppStringUtils.formatEmptyToNull(jsonObject.getString("code")));
		sysCountry.setNameCn(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameCn")));
		sysCountry.setNameEn(AppStringUtils.formatEmptyToNull(jsonObject.getString("nameEn")));
		return sysCountry;
	}

}